# Maintainer: Benedikt Bitterli <benedikt.bitterli@gmail.com>

_realname=rapidjson
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.0
pkgrel=1
pkgdesc='A fast JSON parser/generator for C++ with both SAX/DOM style API (mingw-w64)'
arch=('any')
url='https://github.com/miloyip/rapidjson'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/miloyip/rapidjson/archive/v${pkgver}.tar.gz"
        '0001-Use-relative-paths-for-doxygen-outputs.patch'
        '0002-Add-CMake-check-for-MinGW.patch'
        '0003-Exclude-CMakeLists.txt-from-install-targets.patch'
        '0004-CMake-Install-compiled-example-executables.patch'
        '0005-implicit-fallthrough.patch')
sha256sums=('bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e'
            '5a838fe611b367f8939231aae1f604f83fd97108d3b2ac66def00ff1205afcf2'
            '8160d2ef142055cecb520b23cf11e90e0a6e92719427fa33755800cc748cf8be'
            '04ba9821bb09d5f035093bce09690717101f03851308aa12d498311f11024b02'
            '479b8654f0418aa89f245af4345e5df409ac5a91667815a47592da1b6d5d9eee'
            '0082d3237176b0f5ffae6fed62df9430bfa74f3fa6c4fb82a11ddd0b8990a05a')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-Use-relative-paths-for-doxygen-outputs.patch"
  patch -p1 -i "${srcdir}/0002-Add-CMake-check-for-MinGW.patch"
  patch -p1 -i "${srcdir}/0003-Exclude-CMakeLists.txt-from-install-targets.patch"
  patch -p1 -i "${srcdir}/0004-CMake-Install-compiled-example-executables.patch"
  patch -p1 -i "${srcdir}/0005-implicit-fallthrough.patch"
}

build() {
  [[ -d "build-${CARCH}" ]] && rm -rf "build-${CARCH}"
  mkdir "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX=' \
  ${MINGW_PREFIX}/bin/cmake \
    -G'MSYS Makefiles' \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    "../${_realname}-${pkgver}"

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make install DESTDIR="${pkgdir}"
}
